package labox.innovation.gameserver.network.clientpackets;

import labox.innovation.gameserver.model.ForgeItemList;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.serverpackets.ForgeItemChange;

/**
 * 锻造 物品改变请求
 * 删除物品 增加物品
 * @author zjj
 *
 */
public class RequestForgeItemChange extends L2GameClientPacket {

	private static final String RequestForgeItemChange = "[C] 0x7f RequestForgeItemChange";

	private long _itemId; //物品uid

	private int _count; //数量

	private int _op; //0:增加 1:删除

	public static final int FORGE_OP_ADD = 0;

	public static final int FORGE_OP_DEL = 1;

	@Override
	public String getType() {
		return RequestForgeItemChange;
	}

	@Override
	protected void readImpl() {
		// TODO Auto-generated method stub
		_itemId = readLong();
		_count = readInt();
		_op = readByte();

	}

	@Override
	protected void runImpl() {
		final FuzePcInstance player = getClient().getActiveChar();
		if (player == null)
			return;
		final ForgeItemList forgeList = player.getActiveForgeItemList();
		if (forgeList == null) {
			return;
		}

		ForgeItemList.ForgeItem item = null;
		if (_op == FORGE_OP_ADD) {
			item = forgeList.addItem(_itemId, _count);
		} else {
			item = forgeList.removeItem(_itemId, _count);
		}

		if (item != null) {
			player.sendPacket(new ForgeItemChange(item, _op, forgeList.getForgeType()));
		}
	}

}
